package com.rayinhz.bet.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.rayinhz.bet.domain.UserDO;
import com.rayinhz.bet.mapper.UserMapper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 
 * BaseController.java created at 2017年8月8日 下午1:11:20
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/

@Slf4j
@RestController
@Api(value = "/rest", description = "公用接口")
public class PubController {
	@Autowired
	private UserMapper userMapper;
	
	@RequestMapping("/sayHello")
	@ApiOperation(value="sayHello", httpMethod="GET")
	public String sayHello(@RequestParam String name) {
		return "hello:"+name;
	}
	
	@RequestMapping(value="/user", method=RequestMethod.GET)
	@ApiOperation(value="获取用户")
	@ApiResponses({@ApiResponse(code=500, message="自定义错误"),@ApiResponse(code = 100, message = "哟吼")})
	public UserDO getUser(@RequestParam String account) {
		log.info("message logback------->");
		return userMapper.getUserByAccount(account);
	}
	
	@RequestMapping("/setUser")
	@ApiOperation(value = "创建用户", notes = "根据User对象创建用户", httpMethod="POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long", paramType = "form"),
            @ApiImplicitParam(name = "name", value = "用户名", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "age", value = "年龄", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "ipAddr", value = "ip哟", required = false, dataType = "String", paramType = "form")
    })
	public String setUser(@ApiIgnore UserDO userDO) {
		return "success";
	}
	
}
